package b.i.d;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.util.Log;
import b.i.b.f;
import b.i.c.b.c;
import b.i.c.b.d;
import java.io.File;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/* compiled from: TypefaceCompatApi21Impl */
public class e extends k {
    public static Class<?> b = null;
    public static Constructor<?> c = null;
    public static Method d = null;
    public static Method e = null;
    public static boolean f = false;

    public static boolean f(Object obj, String str, int i, boolean z) {
        g();
        try {
            return ((Boolean) d.invoke(obj, new Object[]{str, Integer.valueOf(i), Boolean.valueOf(z)})).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }

    public static void g() {
        Method method;
        if (!f) {
            Class cls;
            Method method2;
            f = true;
            Constructor constructor = null;
            try {
                cls = Class.forName("android.graphics.FontFamily");
                Constructor constructor2 = cls.getConstructor(new Class[0]);
                method2 = cls.getMethod("addFontWeightStyle", new Class[]{String.class, Integer.TYPE, Boolean.TYPE});
                constructor = Typeface.class.getMethod("createFromFamiliesWithDefault", new Class[]{Array.newInstance(cls, 1).getClass()});
                method = constructor;
                constructor = constructor2;
            } catch (ClassNotFoundException | NoSuchMethodException e) {
                Log.e("TypefaceCompatApi21Impl", e.getClass().getName(), e);
                method = constructor;
                cls = method;
                method2 = cls;
            }
            c = constructor;
            b = cls;
            d = method2;
            e = method;
        }
    }

    public Typeface a(Context context, c cVar, Resources resources, int i) {
        g();
        try {
            Object newInstance = c.newInstance(new Object[0]);
            d[] dVarArr = cVar.a;
            int length = dVarArr.length;
            int i2 = 0;
            while (i2 < length) {
                d dVar = dVarArr[i2];
                File z0 = f.z0(context);
                if (z0 == null) {
                    return null;
                }
                try {
                    if (!f.b0(z0, resources, dVar.f)) {
                        z0.delete();
                        return null;
                    } else if (f(newInstance, z0.getPath(), dVar.b, dVar.c)) {
                        z0.delete();
                        i2++;
                    } else {
                        z0.delete();
                        return null;
                    }
                } catch (RuntimeException unused) {
                    z0.delete();
                    return null;
                } catch (Throwable th) {
                    z0.delete();
                    throw th;
                }
            }
            g();
            try {
                Array.set(Array.newInstance(b, 1), 0, newInstance);
                return (Typeface) e.invoke(null, new Object[]{r9});
            } catch (IllegalAccessException | InvocationTargetException th2) {
                throw new RuntimeException(th2);
            }
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException th22) {
            throw new RuntimeException(th22);
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:18:0x0055 A:{SYNTHETIC, Splitter:B:18:0x0055} */
    public android.graphics.Typeface b(android.content.Context r4, android.os.CancellationSignal r5, b.i.h.e.c[] r6, int r7) {
        /*
        r3 = this;
        r0 = r6.length;
        r1 = 0;
        r2 = 1;
        if (r0 >= r2) goto L_0x0006;
    L_0x0005:
        return r1;
    L_0x0006:
        r0 = new b.i.d.j;
        r0.m5056init(r3);
        r6 = b.i.d.k.e(r6, r7, r0);
        r6 = (b.i.h.e.c) r6;
        r7 = r4.getContentResolver();
        r6 = r6.a;	 Catch:{ IOException -> 0x008b }
        r0 = "r";
        r5 = r7.openFileDescriptor(r6, r0, r5);	 Catch:{ IOException -> 0x008b }
        if (r5 != 0) goto L_0x0025;
    L_0x001f:
        if (r5 == 0) goto L_0x0024;
    L_0x0021:
        r5.close();	 Catch:{ IOException -> 0x008b }
    L_0x0024:
        return r1;
    L_0x0025:
        r6 = new java.lang.StringBuilder;	 Catch:{ ErrnoException -> 0x0052 }
        r6.<init>();	 Catch:{ ErrnoException -> 0x0052 }
        r7 = "/proc/self/fd/";
        r6.append(r7);	 Catch:{ ErrnoException -> 0x0052 }
        r7 = r5.getFd();	 Catch:{ ErrnoException -> 0x0052 }
        r6.append(r7);	 Catch:{ ErrnoException -> 0x0052 }
        r6 = r6.toString();	 Catch:{ ErrnoException -> 0x0052 }
        r6 = android.system.Os.readlink(r6);	 Catch:{ ErrnoException -> 0x0052 }
        r7 = android.system.Os.stat(r6);	 Catch:{ ErrnoException -> 0x0052 }
        r7 = r7.st_mode;	 Catch:{ ErrnoException -> 0x0052 }
        r7 = android.system.OsConstants.S_ISREG(r7);	 Catch:{ ErrnoException -> 0x0052 }
        if (r7 == 0) goto L_0x0052;
    L_0x004a:
        r7 = new java.io.File;	 Catch:{ ErrnoException -> 0x0052 }
        r7.<init>(r6);	 Catch:{ ErrnoException -> 0x0052 }
        goto L_0x0053;
    L_0x0050:
        r4 = move-exception;
        goto L_0x0082;
    L_0x0052:
        r7 = r1;
    L_0x0053:
        if (r7 == 0) goto L_0x0064;
    L_0x0055:
        r6 = r7.canRead();	 Catch:{ all -> 0x0050 }
        if (r6 != 0) goto L_0x005c;
    L_0x005b:
        goto L_0x0064;
    L_0x005c:
        r4 = android.graphics.Typeface.createFromFile(r7);	 Catch:{ all -> 0x0050 }
        r5.close();	 Catch:{ IOException -> 0x008b }
        return r4;
    L_0x0064:
        r6 = new java.io.FileInputStream;	 Catch:{ all -> 0x0050 }
        r7 = r5.getFileDescriptor();	 Catch:{ all -> 0x0050 }
        r6.<init>(r7);	 Catch:{ all -> 0x0050 }
        r4 = r3.c(r4, r6);	 Catch:{ all -> 0x0078 }
        r6.close();	 Catch:{ all -> 0x0050 }
        r5.close();	 Catch:{ IOException -> 0x008b }
        return r4;
    L_0x0078:
        r4 = move-exception;
        r6.close();	 Catch:{ all -> 0x007d }
        goto L_0x0081;
    L_0x007d:
        r6 = move-exception;
        r4.addSuppressed(r6);	 Catch:{ all -> 0x0050 }
    L_0x0081:
        throw r4;	 Catch:{ all -> 0x0050 }
    L_0x0082:
        r5.close();	 Catch:{ all -> 0x0086 }
        goto L_0x008a;
    L_0x0086:
        r5 = move-exception;
        r4.addSuppressed(r5);	 Catch:{ IOException -> 0x008b }
    L_0x008a:
        throw r4;	 Catch:{ IOException -> 0x008b }
    L_0x008b:
        return r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.i.d.e.b(android.content.Context, android.os.CancellationSignal, b.i.h.e$c[], int):android.graphics.Typeface");
    }
}
